﻿using System.Collections.Generic;
using System.Net.DnsToolkit.Packet;
using System.Net.DnsToolkit.Packet.Busy;
namespace System.Net.DnsToolkit.Resolver {
    public class INAQueryBuilder : IQueryBuilder {

        private readonly IHeaderIdGenerator _idGenerator;

        public INAQueryBuilder(IHeaderIdGenerator idGenerator) {
            _idGenerator = idGenerator;
        }

        public IMessage Build(string name) {

            var query = new Message {
                Header = new Header {
                    Id = _idGenerator.Generate(),
                    QueryType = QREnum.QUERY,
                    OpCode = OpCodeEnum.StandardQuery,
                    // AuthoritativeAnswer = false,
                    // Truncation = false,
                    RecursionDesired = true,
                    // RecursionAvailable = false,
                    // Reserved = false,
                    // AnswerAuthenticated = false,
                    // NotAuthenticatedAcceptable = true,
                    // ResponseCode = RCodeEnum.NoError,
                    // counts
                    QuestionCount = 1,
                    // ResourceCount = 0,
                    // AnswerCount = 0,
                    // AuthorityCount = 0,
                },
                Questions = new List<IQuestion> {
                    new Question {
                        QName = new DomainName { Name = name },
                        QType = QTypeEnum.A,
                        QClass = QClassEnum.IN
                    }
                }
            };

            return query;

        }

    }
}
